﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace Dapper.Moon
{
    public class MySqlUpdateable<T> : UpdateableProvide<T>
    {
        public MySqlUpdateable(IDatabase _Repository)
            : base(_Repository) { }

        public override SqlBuilderResult ToSql()
        {
            SqlBuilderResult sqlResult = GetSqlParam();
            string sql = "update {0} set {1} where {2}";
            if (_Limit.HasValue)
            {
                sql += " limit " + _Limit;
            }
            return new SqlBuilderResult()
            {
                Sql = string.Format(sql, 
                IsQuote ? Database.SqlDialect.SetSqlName(MasterTableName) : MasterTableName,
                sqlResult.Sql, _Where.Sql),
                DynamicParameters = sqlResult.DynamicParameters
            };
        }
    }
}
